package com.zxy.ider.ehome.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ider.deskcust.TileEntry;
import com.zxy.ider.ehome.Appcontext;
import com.zxy.ider.ehome.R;
import com.zxy.ider.ehome.util.GlideCircleTransform;

/**
 * Created by ider-eric on 2017/5/27.
 */

public class HomeGridAdapter extends BaseAdapter {
    private TileEntry[] tileEntrys;

    public HomeGridAdapter(TileEntry[] tileEntrys) {
        this.tileEntrys = tileEntrys;
    }

    @Override
    public int getCount() {
        return tileEntrys.length;
    }

    @Override
    public Object getItem(int i) {
        return tileEntrys[i];
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        GridViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new GridViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.homegrid_item, parent, false);
            viewHolder.iconview = (ImageView) convertView.findViewById(R.id.tool_icon);
            viewHolder.titleview = (ImageView) convertView.findViewById(R.id.tool_title);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (GridViewHolder) convertView.getTag();
        }
        Glide.with(Appcontext.getAppContext()).load(tileEntrys[position].strupic).crossFade().into(viewHolder.iconview);//.transform(new GlideCircleTransform(Appcontext.getAppContext()))
        Glide.with(Appcontext.getAppContext()).load(tileEntrys[position].strutitle).into(viewHolder.titleview);
        return convertView;
    }

    class GridViewHolder {
        public ImageView iconview, titleview;
    }

}
